<template>
  <header class="workstation-header">
    <div class="title-wrapper">
      <img src="../assets/png/logo.png" alt="logo" class="logo">
      <h2>{{ workstationName }}</h2>
    </div>
    <el-tabs :model-value="activeTab" type="card" @tab-change="handleTabChange">
      <el-tab-pane v-for="tab in tabs" :key="tab.id" :label="tab.label" :name="tab.id">
      </el-tab-pane>
    </el-tabs>

    <div class="header-right">
      <span class="user-info">欢迎您：{{ user.name }}（{{ user.department }} - {{ user.role }}）</span>
      <el-dropdown trigger="click" @command="changeTheme">
        <el-button type="text" class="theme-switcher">
          <el-icon :size="20" color="var(--text-secondary)">
            <svg viewBox="0 0 1024 1024">
              <path d="M512 512m-512 0a512 512 0 1 0 1024 0 512 512 0 1 0-1024 0Z" fill="var(--primary)"></path>
              <path d="M512 128a384 384 0 0 1 0 768v-768z" fill="var(--text)"></path>
            </svg>
          </el-icon>
        </el-button>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="default">
              <span style="color: #007080">●</span> 默认主题
            </el-dropdown-item>
            <el-dropdown-item command="tech-blue">
              <span style="color: #00a0e9">●</span> 科技蓝
            </el-dropdown-item>
            <el-dropdown-item command="medical-green">
              <span style="color: #5cb85c">●</span> 医疗绿
            </el-dropdown-item>
            <el-dropdown-item command="dark">
              <span style="color: #333">●</span> 暗黑模式
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </header>
</template>

<script lang="ts" setup>
import { type PropType } from 'vue'
import { ElTabs, ElTabPane } from 'element-plus'

export interface TabItem {
  id: string
  label: string
}

const props = defineProps<{
  workstationName: string
  tabs: TabItem[]
  activeTab: string
}>()

const emit = defineEmits(['tab-change'])

const handleTabChange = (tabId: string | number) => {
  emit('tab-change', tabId.toString())
}

import { useThemeStore } from '../stores/theme'
import type { Theme } from '../stores/theme'

const themeStore = useThemeStore()
const changeTheme = (theme: Theme) => {
  themeStore.setTheme(theme)
}

const user = {
  name: '张医生',
  department: 'ICU',
  role: '主治医师'
}
</script>

<style scoped>
.workstation-header {
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--primary-bg);
  color: var(--text);
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease;
  gap: 1px;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

.theme-switcher {
  padding: 0 10px;
  margin-left: 10px;
  border-radius: 4px;
  transition: all 0.3s;
}

.theme-switcher:hover {
  background: rgba(var(--primary-rgb), 0.1);
}

.theme-switcher:active {
  background: rgba(var(--primary-rgb), 0.2);
}

.title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  width: 307px;
  min-width: 180px;
  color: var(--text-secondary);
}

.logo {
  height: 70%;
  max-height: 32px;
  width: auto;
  object-fit: contain;
  margin-left: 5px;
}

/* 调整el-tabs样式与头部高度一致 */
:deep(.el-tabs__header) {
  margin: 0;
  height: 100%;
  border-bottom: none;
}

:deep(.el-tabs__nav-wrap) {
  height: 100%;
}

:deep(.el-tabs__nav-scroll) {
  height: 100%;
  display: flex;
  align-items: center;
}

:deep(.el-tabs__item) {
  height: 100%;
  min-height: 40px;
  line-height: 40px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  border: none !important;
  background: transparent !important;
  margin: 0;
  margin-bottom: 1px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

:deep(.el-tabs__item.is-active) {
  color: var(--text);
  background: var(--bg) !important;
  border-radius: 0px;
  font-weight: 600;
}

:deep(.el-tabs--card > .el-tabs__header .el-tabs__nav) {
  border: none !important;
}

:deep(.el-tabs--card > .el-tabs__header .el-tabs__item) {
  border: none !important;
}
</style>
